package de.baumann.browser.views.widget;

import android.content.Context;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import de.baumann.browser.R;

/**
 * @author：
 * @date：2018/11/28
 * @discription: 顶部搜索栏
 **/
public class FloatSearchBar extends FrameLayout {
    TextView mTvFloatSearchTitle;
    ProgressBar mFloatSearchProgress;
    public ImageView mFloatSearchRefresh;

    public FloatSearchBar(@NonNull Context context) {
        this(context, null);
    }

    public FloatSearchBar(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public FloatSearchBar(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        this(context, attrs, defStyleAttr, 0);
    }

    public FloatSearchBar(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        LayoutInflater.from(context).inflate(R.layout.layout_float_searchbar, this, true);
        mTvFloatSearchTitle = findViewById(R.id.tvFloatSearchTitle);
        mFloatSearchProgress = findViewById(R.id.pbFloatSearchProgress);
        mFloatSearchRefresh = findViewById(R.id.ivFloatSearchRefresh);
    }

    public void setTitle(CharSequence title) {
        this.mTvFloatSearchTitle.setText(title);
    }

    public void setprogress(int progress) {
        mFloatSearchProgress.setVisibility(VISIBLE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            mFloatSearchProgress.setProgress(progress, true);
        } else {
            mFloatSearchProgress.setProgress(progress);
        }
    }
}
